//
//  ZWTabBarController.m
//  20240823
//
//  Created by 张伟 on 2024/8/24.
//

#import "ZWTabBarController.h"

@interface ZWTabBarController ()

@end

@implementation ZWTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configTabBar];
    [self login];
}

-(void)configTabBar {
    UITabBarAppearance * tabbar = UITabBarAppearance.new;
    tabbar.backgroundColor = UIColor.whiteColor;
    self.tabBar.standardAppearance = tabbar;
    self.tabBar.scrollEdgeAppearance = tabbar;
}

-(void)login{
    NSString * account = [NSUserDefaults.standardUserDefaults valueForKey:accountKey];
    NSString * password = [NSUserDefaults.standardUserDefaults valueForKey:passwordKey];

    if (account.length > 0) {
        [NetService requestLogin:account password:password successHandle:^{
            [NSNotificationCenter.defaultCenter postNotificationName:@"canLoadHomeData" object:nil];
            [SipManager.sharedManager login];
        } fail:^{
            [ZWTools cleanUserData];
            [VCRouter toLoginController];
        }];
    }else{
        [VCRouter toLoginController];
    }
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    if (UserModel.shared.isLogin == false) {
        [self login];
    }
}

@end
